package com.nebula.maven.springbootmebula.nebula;


import com.nebula.maven.springbootmebula.beetl.NebulaImpl;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nebula")
public class NebulaController {
    private final NebulaService nebulaService;
    private final NebulaImpl nebulaImpl;

    public NebulaController(NebulaService nebulaService, NebulaImpl nebulaImpl) {
        this.nebulaService = nebulaService;
        this.nebulaImpl = nebulaImpl;
    }

    @PostMapping("/user")
    public NebulaResult addUser(@RequestParam Long userId,
                             @RequestParam String name,
                             @RequestParam Integer age) {
        return nebulaService.addUser(userId, name, age);
    }

    @PutMapping("/user")
    public NebulaResult updateUser(@RequestParam Long userId,
                                @RequestParam String name,
                                @RequestParam Integer age) {
        return nebulaService.updateUser(userId, name, age);
    }

    @GetMapping("/user")
    public NebulaResult getUser(@RequestParam Long userId) {
        return nebulaService.getUser(userId);
    }

    @DeleteMapping("/user")
    public NebulaResult deleteUser(@RequestParam Long userId) {
        return nebulaService.deleteUser(userId);
    }

    @GetMapping("/testBeetl")
    public NebulaResult testBeetl(@RequestParam String name) {
        return nebulaImpl.queryUser(name);
    }
}

